<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>商品表管理</title>
    <meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
    <jsp:include page="../com/header.jsp"></jsp:include>
    <script type="text/javascript" src="../../js/comm/listcomm.js"></script>
    <script type="text/javascript">
        var contentUrl = root + "cms/shop/findShopNEStatusPage";
        var shopCagetoryUrl = root + "cms/category/findShopCategoryNEStatusPage";
        var editUrl = 'shopEdit.jsp?id=';
        var operateUrl = root + 'cms/shop/operateShopByIds';
        function getfilter() {
            var _jsonFilter = "{";
            if ($("#search_shopProductName").val() && $("#search_shopProductName").val().length > 0) {
                _jsonFilter += "'search_LIKEIGNORE_shopProductName':'" + $("#search_shopProductName").val().replace("'", "\"") + "',";
            }
            if ($("#search_categoryType").val() && $("#search_categoryType").val().length > 0) {
                _jsonFilter += "'search_EQ_categoryType':'" + $("#search_categoryType").val().replace("'", "\"") + "',";
            }
            if (_jsonFilter != "{") {
                _jsonFilter = _jsonFilter.substring(0, _jsonFilter.length - 1);
            }
            _jsonFilter += "}";
            return _jsonFilter;
        }

        $(document).ready(function () {
            //加载商品分类
            getShopCategories();

            //添加商品分类选择时间
            $('#search_categoryType').change(function () {
                //获取下拉框选中项的text属性值
                var selectID = $("#search_categoryType").find("option:selected").val();
                console.log('option select id:' + selectID);

                dipscontent(getfilter(), contentUrl);
            });

            //$( document ).tooltip();
        });
        function getShopCategories() {
            $.ajax({
                url: shopCagetoryUrl,
                data: {
                    nextPage: 0,
                    pageSize: 99999,
                    sortData: null,
                    jsonFilter:"{'search_EQ_type':'1'}"
                },
                type: 'POST',
                timeout: 7000,
                dataType: 'json'
            }).done(function (data) {
                if (data.code == 1) {
                    var _html = "<option value='' selected>请选择</option>";
                    for (var i = 0; i < data.object.content.length; i++) {
                        _html += "<option value='" + data.object.content[i].id + "'>" + data.object.content[i].categoryName + "</option>";
                    }
                    $('#search_categoryType').html(_html);
                } else {
                    myAlert(data.message || tipMessage.undefined_msg);
                }
            }).fail(function (jqXHR, textStatus, errorThrown) {
                if (textStatus == "timeout") {
                    myAlert(tipMessage.timeout_msg || "请求超时");
                } else {
                    myAlert(tipMessage.error_msg);
                }
            });
        }
    </script>
</head>
<body>
<section>
    <div>
        <div class="col-xs-12">
            <div class="box">
                <form id="search_form" class="form-horizontal">
                    <div class="tabSelect" id="selectHeadId">
                        <br>
                        <div class="form-group  col-md-3 search-form">
                            <label class="col-md-4 control-label controls">商品名称：</label>
                            <div class="col-md-8">
                                <input type="text" placeholder="商品名称" class="form-control input-sm"
                                       id="search_shopProductName" name="shopProductName"/>
                            </div>
                        </div>
                        <div class="form-group  col-md-3 search-form">
                            <label class="col-md-4 control-label controls">商品分类：</label>
                            <div class="col-md-8">
                                <select name="search_categoryType" id="search_categoryType"
                                        class="form-control input-sm"></select>
                            </div>
                        </div>
                        <input type="button" value="查询" id="search" class="btn btn-primary searchBtn">
                    </div>
                </form>
                <div class="box-body table-responsive" style="clear:both;">
                    <input type="button" value="新增" id="addSome" class="btn btn-success">
                    <input type="button" value="编辑" id="updateSome" class="btn btn-color">
                    <input type="button" value="删除" id="deleteSome" class="btn btn-color">
                    <input type="button" value="上架" id="openSome1" class="btn btn-color">
                    <input type="button" value="下架" id="lockSome1" class="btn btn-color">
                </div>
                <div class="box-body table-responsive">
                    <table id="example2" class="table table-bordered table-hover">
                        <thead>
                        <tr>
                            <th width="30"><input type="checkbox" id="_selectAll"/></th>
                            <th width="100">商品名称</th>
                            <th width="30">分类</th>
                            <th width="30">原价</th>
                            <th width="30">优惠价格</th>
                            <th width="30">抵扣比例</th>
                            <th width="30">库存</th>
                            <th width="80">商品图片(首图)</th>
                            <th width="30">排序值</th>
                            <th width="30">点击量</th>
                            <th width="30">状态</th>
                        </tr>
                        </thead>
                        <!-- 表格内容 start -->
                        <tbody id="mycontent"></tbody>
                        <!-- 表格内容 end -->
                    </table>
                    <!-- 分页标签 start -->
                    <div class="row page_big_div" id="displayPage"></div>
                    <!-- 分页标签 end -->
                    <script id="tableContentTmple" type="text/x-jsrender">
								<tr>
									<td><input id="ck_{{:id}}" ckId="{{:id}}" ckStatus="{{:status}}" class="ckSelect" type="checkbox" /></td>
									<td title="{{:shopProductName}}" style="text-align: left" >{{subStrings:shopProductName lens=20}}</td>
									<td>{{if shopCategoryVo}}{{:shopCategoryVo.categoryName}}{{/if}}</td>
									<td title={{:originalPrice}} style="vertical-align:middle; text-align:right;">{{toThousands:originalPrice}}</td>
									<td title={{:shopProductPrice}} style="vertical-align:middle; text-align:right;">{{toThousands:shopProductPrice}}</td>
									<td>{{:discountRate}}</td>
									<td>{{:shopProductInventory}}</td>
									<td id="layer-photos-demo{{:id}}" class="layer-photos-demo">
                                        {{if shopProductPicUrls}}
                                             {{for shopProductPicUrls.split(",")}}
                                                <img {{if #index >= 1}}hidden="hidden"{{/if}}
                                                    layer-src="../../{{:}}"
                                                    layer-pid="{{:id}}"
                                                    src="../../{{:}}"
                                                    alt=""
                                                    layer-index="{{:#parent.parent.id}}"
                                                    height="80" width="80">
                                            {{/for}}
                                        {{else}}
                                            <img src="" height="40" width="50">
                                        {{/if}}
									</td>
									<td>{{:sort}}</td>
									<td>{{:clickCont}}</td>
									<td>{{if status==1}}未上架{{else status==2}}已上架{{else status==3}}已删除{{else}}无效{{/if}}</td>
								</tr>


                    </script>
                </div>
            </div>
        </div>
</section>
</body>
</html>